<!DOCTYPE html>
<html>
<#include "../head.html">

    <body>
    <div class="mc">
        <div class="mc-l">
            <!--左侧导航---{-->
            <div id="navPanelContainer">
                <div class="system-logo cd"></div>
                <!--管理员信息---{-->
                <#include "../adminInfo.html">
                    <!--管理员信息---}-->
                    <div class="nav-wrap">
                        <#include "left.html">
                    </div>
            </div>
            <!--左侧导航---}-->
        </div>
        <div class="mc-m">
            <div class="navToggle"></div>
        </div>
        <div class="mc-r">
            <!--顶部导航---{-->
            <#include "../topNav.html">
                <!--顶部导航---}-->

                <!--面包屑导航---{-->

                <#assign moduleName="发送短信">

                    <#include "banner.html">
                        <!--面包屑导航---}-->

                        <!--工具栏--{-->
                        <div id="toolbar" class="clearfix">

                            <div class="toolbor-module search">

                            </div>

                        </div>


                        <!--工具栏--}-->

                        <div id="main" class="clearfix">
                            <div class="val clearfix">
                                <ul>

                                    <li>
                                        手机：<input id="phoneNum" type="text" name="phoneNum" style="width:150px;"/>
                                        真名：<input id="realName" type="text" name="realName" style="width:150px;"/>
                                        用户名：<input id="userName" type="text"  name="userName" style="width:150px;"></input>
                                        <input id="searchAdd" type="button" value="搜索并添加到发送列表"/>
                                    </li>
                                    <form id="cust" name="form1" method="post" action="/admin/crm/sendCustomerSms.html">
                                        <li>
                                            选择模板
                                            <select name="choose" id="template">
                                                <option value="0" selected="selected">请选择模板</option>

                                                <option value="2">自我介绍</option>
                                                <option value="3">余额提醒</option>
                                                <option value="4">活动奖励</option>
                                                <option value="1" >申购短信</option>
                                            </select>

                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;字数统计<label id="count" >0</label>/70&nbsp;&nbsp;&nbsp;<font color="red">(提示：【钱内助】不能省略)</font>
                                            <br>
                                            <textarea id="msg" name="msg" rows="4" cols="100"></textarea>
                                        </li>

                                        <li>
                                            短信服务商<input type="radio" name="smsMerchant"  value="webpower" checked="checked"/>webpower<br>
                                            发送列表<br>
                                            <textarea id="phoneList" name="phoneList" rows="10" cols="100"></textarea>
                                            <input type="button" id="sendSms" value="发送短信"/>
                                        </li>
                                    </form>
                                </ul>
                                <div class="other">

                                </div>
                            </div>
                            <div>
                                投资次数：
                                <select id="tenderTimes" name="tenderTimes">
                                    <option value="0" selected="selected">全部</option>
                                    <option value="-1">0次</option>
                                    <option value="1">1~3次</option>
                                    <option value="2">3次以上</option>
                                </select>
                                <br>
                                投资金额：
                                <input type="text" id="tenderMoneyMin" name="tenderMoneyMin" onkeyup="value=value.replace(/[^0-9.]/g,'')"> （元）
                                到
                                <input type="text" id="tenderMoneyMax" name="tenderMoneyMax" onkeyup="value=value.replace(/[^0-9.]/g,'')"> （元）
                                <br>
                                投资时间：
                                <input type="text" id="firstTenderTime" name="firstTenderTime" onclick="change_picktime('yyyy-MM-dd')"/>
                                到
                                <input type="text" id="lastestTenderTime" name="lastestTenderTime" onclick="change_picktime('yyyy-MM-dd')"/>
                                <br>
                                投资到期时间：
                                <input type="text" id="expireStart" name="expireStart" onclick="change_picktime('yyyy-MM-dd')"/>
                                到
                                <input type="text" id="expireEnd" name="expireEnd"/ onclick="change_picktime('yyyy-MM-dd')">
                                <br>
                                注册时间：
                                <input type="text" id="regStart" name="regStart" onclick="change_picktime('yyyy-MM-dd')"/>
                                到
                                <input type="text" id="regEnd" name="regEnd" onclick="change_picktime('yyyy-MM-dd')"/>
                                <br>
                                <input type="button" id="searchBtn" value="筛选发送对象"/>
                                <input type="button" id="resetBtn" value="重置"/>
                            </div>
                            <br>
                            <table id="userTable" >

                                <tr >
                                    <td><input type="button" id="allCheck" value="全选"/></td>
                                    <td>   <input type="button" id="allCancle" value="全部取消"/>     </td>
                                </tr>

                                <tr class="header">
                                    <td></td>
                                    <td>用户名</td>
                                    <td>姓名</td>
                                    <td>手机</td>

                                </tr>
                                <#list list as item>
                                    <tr  class="list">
                                        <td><input type="checkbox"  name="phoneCheckbox" value="${item.phone!''}"/></td>
                                        <td>${item.userName!''}</td>
                                        <td>${item.realName!''}</td>
                                        <td>${item.phone!''}</td>
                                    </tr>
                                </#list>
                            </table>
                            <input  type="hidden" id="custfmId" name ="fmId">
                            <input  type="hidden" id="sysPhone" value ="${sysPhone!'15158XXXXXX'}">
                            <input  type="hidden" id="sysName" value ="${sysName!'XXX'}">


                            <!--底部工具栏--{-->
                            <div id="bottomToolbar" class="clearfix">

                            </div>
                            <!--底部工具栏--}-->
                        </div>
        </div>
    </div>
    <div class="mc-b">
        <#include "../foot.html">
    </div>
    <#include "../jsPage.html">
        <script type="text/javascript">
            String.prototype.endWith=function(s){
                if(s==null||s==""||this.length==0||s.length>this.length)
                    return false;
                if(this.substring(this.length-s.length)==s)
                    return true;
                else
                    return false;
                return true;
            }

            String.prototype.replaceAll  = function(s1,s2){
                return this.replace(new RegExp(s1,"gm"),s2);
            }
            var msg = $("#msg");
            var phoneList = $("#phoneList");
            /*
            字数统计
            */
            function count(){
                var msgVal = $("#msg").val();
                $("#count").text(msgVal.length);
            }


            //模板内容填充
            $("#template").change(function(){
                var tlVal = $("#template").val();


                var fmName= $("#sysName").val();
                var fmPhone=$("#sysPhone").val();

                if(1 == tlVal){
                    msg.val("尊敬的用户，钱内助为您提供高收益产品，年化收益XX%，XXX元起售，期限XX天，预约理财经理"+fmName+"-"+fmPhone+"。【钱内助】");
                }else if(2 == tlVal){
                    msg.val("尊敬的钱内助用户，非常感谢您对钱内助的关注，我是您的VIP理财经理"+fmName+"，全方面为您提供理财咨询。联系方式"+fmPhone+"。【钱内助】");
                }else if(3 == tlVal){
                    msg.val("尊敬的钱内助用户，我是您的理财经理"+fmName+"，您尚有有可用资金，不要忘记给您的财富做个升级！若有疑问，请致电"+fmPhone+"【钱内助】");
                }else if(4 == tlVal){
                    msg.val("尊敬的钱内助用户，我是您的理财经理"+fmName+"，您的活动奖励已经发放，请注意查收！若有疑问，请致电"+fmPhone+"【钱内助】");
                }else{
                    msg.val("");
                }
                count();
            });
            $("#msg").keyup(function(){
                count();
            });

            //搜索并添加
            $("#searchAdd").click(function(){

                $.ajax({
                    type: "post",
                    url: "/admin/crm/queryCustomerPhone.html",
                    data: {userName:$("#userName").val(), realName:$("#realName").val(),phoneNum:$("#phoneNum").val()},
                    dataType: "json",
                    success: function(data){
                        if(data.resultCode==1){
                            var phoneVal = phoneList.val();
                            //判断是否存在
                            if(phoneVal.indexOf(data.resultData.phone) == -1){
                                phoneList.val(phoneVal+data.resultData.phone+",");
                            }else{
                                alert("发送列表中已存在");
                            }

                        }else{
                            alert(data.resultMsg);
                        }
                    }
                });
            });
            function addClickFun(Obj){
                if (true == Obj.attr("checked")) {
                    var phoneVal = phoneList.val();
                    //判断是否存在
                    if(phoneVal.indexOf(Obj.val()) == -1){
                        phoneList.val(phoneVal+Obj.val()+",");
                    }

                }else{
                    var phoneVal = phoneList.val();
                    var newA = phoneVal.replaceAll(Obj.val()+",","").replaceAll(Obj.val(),"");
                    phoneList.val(newA);
                }
            }
            //单选
            $("input[name='phoneCheckbox']").click(function(){
                addClickFun($(this));
            });
            //全选
            $("#allCheck").click(function(){
                $("input[name='phoneCheckbox']").attr("checked",true);
                $("input[name='phoneCheckbox']").each(function(){
                    addClickFun($(this));
                });
            });
            //全部取消
            $("#allCancle").click(function(){
                $("input[name='phoneCheckbox']").attr("checked",false);
                $("input[name='phoneCheckbox']").each(function(){
                    addClickFun($(this));
                });
            });

            //点击发送短信
            $("#sendSms").click(function(){
                var smsMerchant = $('input[name="smsMerchant"][checked]').val();
                var phoneList = $("#phoneList").val();
                var msgVal = $("#msg").val();
                if(!smsMerchant){
                    alert("请选择短信服务商");
                    return;
                }
                if(!phoneList){
                    alert("请添加发送号码");
                    return;
                }
                if(!msgVal){
                    alert("请输入短信发送内容");
                    return;
                }
                $("#cust").submit();
                /*$.ajax({
                    type: "post",
                    url: "/admin/crm/sendCustomerSms.html",
                    data: {smsMerchant:smsMerchant, phoneList:phoneList,smsContent:msgVal},
                    dataType: "json",
                    success: function(data){
                       if(data && data.resultCode==1){
                           alert("发送成功");
                       }else{
                           alert("发送失败");
                       }
                    }
                });*/
            });

            //重置检索条件
            $("#resetBtn").click(function(){
                $("#tenderTimes").val(0);
                $("#tenderMoneyMin").val("");
                $("#tenderMoneyMax").val("");
                $("#firstTenderTime").val("");
                $("#lastestTenderTime").val("");
                $("#regStart").val("");
                $("#regEnd").val("");
                $("#expireStart").val("");
                $("#expireEnd").val("");
            });


            $("#searchBtn").click(function(){
                var tenderTimes  = $("#tenderTimes").val();
                var tenderTimesMax = 0;
                var tenderTimesMin=0;

                if(tenderTimes==-1 || tenderTimes==0){
                    tenderTimesMax = tenderTimesMin = tenderTimes;
                }else if(tenderTimes==1){
                    tenderTimesMax = 3;
                    tenderTimesMin = 1;
                }else if (tenderTimes==2){
                    tenderTimesMax = 3;
                    tenderTimesMin = -1;
                }
                alert(tenderTimesMax);
                alert(tenderTimesMin);

                var tenderMoneyMin  = $("#tenderMoneyMin").val();
                var tenderMoneyMax  = $("#tenderMoneyMax").val();
                var firstTenderTime  = $("#firstTenderTime").val();
                var lastestTenderTime  = $("#lastestTenderTime").val();
                var regStart  = $("#regStart").val();
                var regEnd  = $("#regEnd").val();
                var expireStart  = $("#expireStart").val();
                var expireEnd  = $("#expireEnd").val();

                $.ajax({
                    type: "post",
                    url: "/admin/crm/queryCrmSmsUserList.html",
                    data: {
                        tenderTimesMax:tenderTimesMax,
                        tenderTimesMin:tenderTimesMin,
                        tenderMoneyMin:tenderMoneyMin,
                        tenderMoneyMax:tenderMoneyMax,
                        firstTenderTime:firstTenderTime,
                        lastestTenderTime:lastestTenderTime,
                        regStart:regStart,
                        regEnd:regEnd,
                        expireStart:expireStart,
                        expireEnd:expireEnd
                    },
                    dataType: "json",
                    success: function(data){
                        $("#userTable .list").remove();
                        if(data && data.length>=1){

                            for(var i=0;i<data.length;i++){
                                var Obj = data[i];
                                var sHtml ='';

                                sHtml +='<tr class="list">'
                                sHtml +='	<td><input type="checkbox"  name="phoneCheckbox" value="'+isNullStr(Obj.phone)+'"/></td>';
                                sHtml +='	<td> '+isNullStr(Obj.userName)+'</td>';
                                sHtml +='	<td> '+isNullStr(Obj.realName)+'</td>';
                                sHtml +='	<td> '+isNullStr(Obj.phone)+'</td>';
                                sHtml +='</tr>';
                                $("#userTable").append(sHtml);
                            }
                        }
                    }
                });
            });

            function isNullStr(str){
                if(str==null || str== "" ||str == undefined ){
                    return '';
                }else{
                    return str;
                }
            }
        </script>
    </body>
</html>
